#include <bits/stdc++.h>
using namespace std;

#define NAME "color"
typedef long long ll;
const int INF = 2e9;
const ll LINF = 4e18;
const int MAXN = 2005;

int n, a[MAXN];
int dp[MAXN][MAXN][2];

void solve(){
    cin >> n;
    a[0] = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for (int i = 0; i <= n + 1; i++){
        for (int j = 0; j <= n; j++){
            dp[i][j][0] = -INF;
            dp[i][j][1] = -INF;
        }
    }
    dp[1][0][0] = 0;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n; j++){
            for (int k = 0; k < 2; k++){
                if (dp[i][j][k] == -INF) continue;
                int red = j, blue = i - 1;
                if (k) swap(red, blue);
                dp[i + 1][red][0] = max(dp[i + 1][red][0], dp[i][j][k] + (a[blue] == a[i]) * a[i]);
                dp[i + 1][blue][1] = max(dp[i + 1][blue][1], dp[i][j][k] + (a[red] == a[i]) * a[i]);
            }
        }
    }
    int ans = 0;
    for (int j = 0; j <= n; j++){
        for (int k = 0; k < 2; k++){
            ans = max(ans, dp[n + 1][j][k]);
        }
    }
    cout << ans << endl;
}

int main(){
    freopen(NAME ".in", "r", stdin);
    freopen(NAME ".out", "w", stdout);

    int t; cin >> t;
    while (t--) solve();
    return 0;
}